package org.dna.opdracht1;

import java.util.Random;

public class RandomOne extends RandomPerm {

	public RandomOne(String name) {
		super(name);
	}

	// T(N) = O(F(N+2^N))
	@Override
	protected int[] randomPerm(int n) {
		int[] array = new int[n];
		Random random = new Random();
		array[0] = random.nextInt(n);

		for(int i = 1; i < n; i++) { // n iterators
			int number = random.nextInt(n); // 1 statement
			int j = 0; // 1 statement
			boolean foundNumber = false; // statement
			while (j < i) { // n*n iterators
				if (array[j] == number) { // 1 statement
					foundNumber = true; // 1 statement
					break;
				}
				j++; // 1 statement
			}
			if (foundNumber) { // 1 statement
				i--; // 1 statement
			} else {
				array[i] = number; // 1 statement
			}
		}
		return array;
	}
}
